#!/bin/env python

import os, optparse

def mkhash(dir, level=0, max=3):
    subdirs = map(lambda x: hex(x)[2:], range(16))
    subdirs = map(lambda x: os.path.join(dir, x), subdirs)
    map(os.mkdir, subdirs)
    if level < max:
        map(lambda x: mkhash(x, level+1), subdirs)

def main():
    parser = optparse.OptionParser(prog="mkhash", description="Creates a directory hash of hex values. For storing a large number of files.")
    parser.add_option("-r", "--root", help="The base directory.")

    (options, args) = parser.parse_args()

    if not options.root:
        parser.error('Root directory is required.')

    mkhash(options.root)

if __name__ == '__main__':
    main()
